/**
 * @author Administrator
 */
var women_popup = {};

women_popup.createTips = function(elem){
	var tparams = elem.getAttribute("tips:params");
	if(tparams){
		var nameValueObj = {};
		elem.onmouseover = function(){
			setTimeout(function(){women_popup.viewPopup(elem);}, 500)
		}
		elem.onmouseout = function(){
			setTimeout(
			    function(){
					var popup = document.getElementById("women-popup");
					if(!popup.getAttribute("mousein")){
						popup.style.display = "none";
					}else if(popup.style.display == "none"){						
						women_popup.viewPopup(elem)
					}
				}, 500
			);
		}
	}
}

women_popup.viewPopup = function(elem){
    var popup = document.getElementById("women-popup");
    var pos = getElementPosition(elem);
	popup.setAttribute("mousein", true);
    popup.style.left = pos.x + elem.offsetWidth + "px";
    popup.style.top = pos.y + "px";
    popup.style.display = "block";
    
	var tparams = elem.getAttribute("tips:params")
    var params = tparams.split("&");
    nameValueObj = {};
    for(var i = 0; i < params.length; i++){
        var param = params[i];
        var c = param.split("=");
        if(c.length == 2){
            var name = c[0], value = c[1];
            nameValueObj[name] = value;
        }
    }
    women_popup.fillData();
	if (!popup.onmouseout) {
		popup.onmouseout = function(e){
			e = e || window.event
			var srcEle = e.srcElement || e.target;
			setTimeout(function(){
				if (srcEle && srcEle.id == "women-popup") {
					srcEle.removeAttribute("mousein");
					popup.style.display = "none";
				}
			}, 500)
		}
	}
}
    
women_popup.fillData = function(){
    var popup = document.getElementById("women-popup");
    var htmlStr = decodeURI(popup.innerHTML);
    while(/\$\{\w+\}/g.test(htmlStr)){
        var name = htmlStr.match(/\$\{\w+\}/);
        name = name[0].match(/\w+/g);
        var reg = new RegExp("\\$\\{" + name + "\\}", "gi");
        htmlStr = htmlStr.replace(reg, nameValueObj[name]);
    }
    popup.innerHTML = htmlStr;
}

function getElementPosition(element) {
    var result = {x: 0, y: 0, width: 0, height: 0};
    if (element.offsetParent) {
        result.x = element.offsetLeft;
        result.y = element.offsetTop;
        var parent = element.offsetParent;
        while (parent) {
            result.x += parent.offsetLeft;
            result.y += parent.offsetTop;
            var parentTagName = parent.tagName.toLowerCase();
            if (parentTagName != "table" &&
                parentTagName != "body" && 
                parentTagName != "html" && 
                parentTagName != "div" && 
                parent.clientTop && 
                parent.clientLeft) {
                result.x += parent.clientLeft;
                result.y += parent.clientTop;
            }
            parent = parent.offsetParent;
        }
    }
    else if (element.left && element.top) {
        result.x = element.left;
        result.y = element.top;
    }
    else {
        if (element.x) {
            result.x = element.x;
        }
        if (element.y) {
            result.y = element.y;
        }
    }
    if (element.offsetWidth && element.offsetHeight) {
        result.width = element.offsetWidth;
        result.height = element.offsetHeight;
    }
    else if (element.style && element.style.pixelWidth && element.style.pixelHeight) {
        result.width = element.style.pixelWidth;
        result.height = element.style.pixelHeight;
    }
    return result;
} 


var elems = document.getElementsByTagName("*");
for(var i = 0, len = elems.length; i < len; i++){
    var elem = elems[i];
    var tparams = elem.getAttribute("tips:params");
    if(tparams){
        women_popup.createTips(elem);
    }
}